home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / .wais / Solaris_2 / makedesc.pl < prev    next >
Perl Script  |  1995-08-22  |  14KB  |  633 lines

  1. #!/net/pinatubo/opt/PUBperl5/bin/perl5
  2. # /export/scratch/illustra/bin/perl5
  3. # /opt/PUBperl5/bin/perl5
  4. #
  5. # makedesc.pl
  6. #
  7. # Generate The Wais Tree
  8. #
  9. # Copyright Creative Dynamics, Inc. 1995
  10. #
  11. #$dirn = $0;
  12. #$dirn =~ s#(.*)/.*$#$1#;
  13. #require "$dirn/common.pl";
  14.  
  15. $CATDB_NAME = "catalyst";
  16. $USER = "miadmin";
  17.  
  18. #
  19. # use the libmi stuff
  20. #
  21.  
  22. use Mi;
  23.  
  24. $lastCategory = "";
  25. $lastSubCategory = "";
  26. $chapterCount = 0;
  27. $fileOpen = 0;
  28.  
  29. ### Set up output directory
  30.  
  31. $outputDirectory = "wais-src";
  32. umask(022);
  33. mkdir($outputDirectory, 0777);        # make an output directory for book    
  34. chdir "$outputDirectory" || die "Can't cd to $outputDirectory\n";
  35. unlink(<*>);                # delete all existing files in the output directory
  36.  
  37. {
  38.    local($query,$num_col, @record);
  39.    local($db, $row_desc, $result, $row, $col, $row_num, $error);
  40.  
  41. ### the query
  42.  
  43. $query = "
  44. select  p.Product_id, p.SolCompatible,    
  45.     p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName,
  46.     p.ProdShortDesc, p.ProdLongDesc,
  47.     p.ProdHomePage, p.ProdImage, p.SrcAvail, p.ProdSrcLang,
  48.     p.ProdSpecHand,
  49.     v.VendorAddr1, v.VendorAddr2, v.VendorAddr3, v.VendorCity,
  50.     v.VendorPostCode,
  51.     v.VendorState, v.VendorZip, v.VendorCountry,
  52.     v.VendorPhone1code, v.VendorPhone1,
  53.     v.VendorPhone2code, v.VendorPhone2,
  54.     v.VendorFaxCode, v.VendorFax,
  55.     v.VendorEmailCode, v.VendorEmail,
  56.     v.VendorURL
  57. from   Vendor v using(lock=table),
  58.        Assoc_ProdVend a using(lock=table),
  59.        Products p using(lock=table)
  60. where  a.ProdId = p.Product_id
  61. and    a.VendId = v.Vendor_id
  62. and    p.Product_id < 10
  63. order by p.ProdCatName, p.ProdSubCat, p.ProdName
  64. ;";
  65.  
  66. # where  p.Product_id < 50 -- use to limit
  67. # alternate order: order by p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName
  68.  
  69. ### query the database
  70.  
  71.    ($db = Mi::open("$CATDB_NAME", "$USER", "") ) || die "Can't open Illustra database\n";
  72.  
  73.    (Mi::exec($db, "$query", 0) == 0) || die "Can't exec Illustra query\n";
  74.  
  75.    print "  Query Sent\n";
  76.  
  77.    (($result = Mi::get_result($db)) == 1) || die "Got bad result from Illustra\n";
  78.  
  79.    print "  Got Results\n";
  80.  
  81.    ($row_desc = Mi::get_row_desc_without_row($db)) || die "Error on row description \n";
  82.  
  83.    $num_col = Mi::column_count($row_desc);
  84.  
  85.    print "  Results Have $num_col Columns\n";
  86.  
  87.    $row_num = 0;
  88.    while ($row = Mi::next_row($db, \$error))
  89.    {
  90.     $row_num++;
  91.     print "   Processing row $row_num...\n";
  92.     foreach $col (0..$num_col-1)
  93.     {
  94.           Mi::value($row, $col, $colval, $retlen);
  95.           $record[$col] = $colval;
  96.     }
  97.  
  98. ### Fix the data
  99.  
  100. # map double occurrences of ' to single '
  101.  
  102.     foreach $count (2..12)
  103.     {
  104.         $record[$count] =~ s/\'\'/\'/g;
  105.     }
  106.  
  107. ### Trim trailing spaces
  108.     foreach $count (2..30)
  109.     {
  110.         $record[$count] =~ s/ *$//g;
  111.     }
  112.  
  113. ### Now print out the data for this product        
  114.  
  115.     if ($lastCategory ne $record[2])
  116.     {
  117.         ++$chapterCount;        # increment chapter count
  118.         $outputChapterName = $record[2];
  119.         $outputChapterName = =~ s/ /_/g;
  120.         mkdir($outputChapterName, 0777);
  121.         chdir "$outputChapterName" || die "Can't cd to $outputChapterName\n";
  122.         unlink(<*>);
  123.         $lastCategory = $record[2];
  124.     }
  125.     if ($lastSubCategory ne $record[3])
  126.     {
  127.         chdir "..";
  128.         $outputSubchapterName = $record[3];
  129.         $outputSubchapterName = =~ s/ /_/g;
  130.         mkdir($outputSubchapterName, 0777);
  131.         chdir "$record[3]" || die "Can't cd to $outputSubchapterName\n";
  132.         unlink(<*>);
  133.         $lastSubCategory = $record[3];
  134.     }
  135.  
  136.     &print_productheader($record[2]);
  137.  
  138.     &print_specialpara("H3", &build_productindex($record[5]), $record[5]);
  139.     &print_specialpara("H4", &build_vendorindex($record[4] . ":" . $record[5]), $record[4]);
  140.  
  141. # 6 p.ProdShortDesc,
  142. # 7 p.ProdLongDesc,
  143.     # choose the Long Description if it exists
  144.     $description = ($record[7] =~ /\S/) ? $record[7] : $record[6];
  145.     &print_multi("P", $description);
  146.  
  147. # 8 p.ProdHomePage,
  148.     if ($record[8] =~ /\S/)
  149.     {
  150.         &print_para("I", $record[8]);
  151.     }
  152.  
  153. # 9 p.ProdImage,
  154.  
  155.     ### NO PRODUCT IMAGE SUPPORT, YET
  156.     #&print_anchor(6);
  157.  
  158. ### TEMP NEED TO FIX THIS 
  159.     # &print_para("P", "Platforms supported: SPARC");
  160.  
  161. # 10 p.SrcAvail,
  162.     $answer = ($record[10] =~ /t/) ? "yes" : "no";
  163.     &print_para("P", "Source available: $answer");
  164.  
  165. # 11 p.ProdSrcLang,
  166.     &print_para("P", "Language: $record[11]");
  167.  
  168. # 12 p.ProdSpecHand,
  169. #
  170. # remove [ and ] brackets, also fix spaces and comma
  171. #
  172.     $record[12] =~ s/^\[//g;
  173.     $record[12] =~ s/ *]$//g;
  174.     $record[12] =~ s/^ *,//g;
  175.     $record[12] =~ s/ +,/, /g;
  176.  
  177.     if ($record[12] =~ /\S/)
  178.     {
  179.         &print_para("P", "Additional Requirements: $record[12]");
  180.     }
  181.  
  182. # 5 v.VendorName,
  183.     &print_para("I", $record[5]);
  184.  
  185. # 13 v.VendorAddr1,
  186. # 14 v.VendorAddr2,
  187. # 15 v.VendorAddr3,
  188.     foreach $count (13..15)
  189.     {
  190.          &print_para("I", $record[$count]) if ($record[$count] =~ /\S/);
  191.     }
  192. # 16 v.VendorCity,
  193. # 17 v.VendorPostCode,
  194. # 18 v.VendorState,
  195. # 19 v.VendorZip,
  196. # 20 v.VendorCountry,
  197.     # $record[16] =~ s/ $//g;
  198.     $address = $record[16] . ",";
  199.     foreach $count (18..20)
  200.     {
  201.         $address .= " " . $record[$count] if ($record[$count] =~ /\S/);
  202.     }
  203.     &print_para("I", $address);
  204.  
  205.     &print_para("I","Postal Code: $record[17]") if ($record[17] =~ /\S/);
  206.  
  207. # 21 v.VendorPhone1code,
  208. # 22 v.VendorPhone1,
  209. # 23 v.VendorPhone2code,
  210. # 24 v.VendorPhone2,
  211. # 25 v.VendorFaxCode,
  212. # 26 v.VendorFax,
  213. # 27 v.VendorEmailCode,
  214. # 28 v.VendorEmail,
  215.  
  216. $text = "";
  217. $text = $record[21] . " " if ($record[21] =~ /\S/);
  218. &print_para("I","Phone1: $text$record[22]") if ($record[22] =~ /\S/);
  219. $text = "";
  220. $text = $record[23] . " " if ($record[23] =~ /\S/);
  221. &print_para("I","Phone2: $text$record[24]") if ($record[24] =~ /\S/);
  222. $text = "";
  223. $text = $record[25] . " " if ($record[25] =~ /\S/);
  224. &print_para("I","Fax: $text$record[26]") if ($record[26] =~ /\S/);
  225. $text = "";
  226. $text = $record[27] . " " if ($record[27] =~ /\S/);
  227. &print_para("I","E-mail: $text$record[28]") if ($record[28] =~ /\S/);
  228.  
  229. # 29 v.VendorURL
  230.  
  231.     &print_para("I",$record[29]) if ($record[29] =~ /\S/);
  232.  
  233. # 30 v.VendorLOGO
  234.  
  235.     ### NO VENDOR IMAGE SUPPORT, YET
  236.     #&print_anchor(6);
  237.  
  238. # End of Product
  239.     &print_para("HR", "");
  240.  
  241.    }
  242.  
  243.    Mi::close($db);
  244.  
  245.    print "Processed $row_num records\n";
  246. }
  247.  
  248.  
  249. ### TEMP TEST OF GRAPHIC
  250.     #&print_anchor(6);
  251.  
  252. # final stuff...
  253. if ($fileOpen)
  254. {
  255.     &print_chapterfooter();
  256.     close CHAPTER;    
  257. }
  258.  
  259. # process book file
  260. &createbook();
  261.  
  262. print "Book Complete\n";
  263.  
  264.  
  265. #------------------------------------------------------------------
  266. # SUBROUTINES
  267. #------------------------------------------------------------------
  268.  
  269. #------------------------------------------------------------------
  270. # build_productindex 
  271. #
  272. # subroutine build_productindex builds MIF for FrameMaker product index markers
  273.  
  274. sub build_productindex {
  275.     return &build_indexmarker(2, @_[0]);
  276. }
  277.  
  278.  
  279. #------------------------------------------------------------------
  280. # build_vendorindex 
  281. #
  282. # subroutine build_vendorindex builds MIF for FrameMaker vendor index markers
  283.  
  284. sub build_vendorindex {
  285.     return &build_indexmarker(2, @_[0]);
  286. }
  287.  
  288.  
  289. #------------------------------------------------------------------
  290. # build_indexmarker 
  291. #
  292. # subroutine build_indexmarker builds MIF for FrameMaker index markers
  293.  
  294. sub build_indexmarker {
  295.  
  296.     local($markerType, $indexEntry) = @_;
  297.  
  298.     return "<Marker <MType $markerType> <MText \`$indexEntry\'>>";
  299. }
  300.  
  301.  
  302. #------------------------------------------------------------------
  303. # print_specialpara 
  304. #
  305. # subroutine print_specialpara prints MIF for FrameMaker paragraph with a special character ie bullet
  306.  
  307. sub print_specialpara {
  308.  
  309.     local($tag) = @_[0];
  310.     local($specialchar) = @_[1]; 
  311.     local($string) = @_[2]; 
  312.  
  313.     print CHAPTER " <Para 
  314.   <PgfTag \`$tag\'>
  315.    <ParaLine $specialchar
  316.     <String \`$string\'>
  317.    >
  318.  > # end of Para\n";
  319. }
  320.  
  321.  
  322. #------------------------------------------------------------------
  323. # print_para 
  324. #
  325. # subroutine print_para prints MIF for FrameMaker paragraph
  326.  
  327. sub print_para {
  328.  
  329.     local($tag) = @_[0];
  330.     local($string) = @_[1]; 
  331.  
  332.     print CHAPTER " <Para 
  333.   <PgfTag \`$tag\'>
  334.    <ParaLine
  335.     <String \`$string\'>
  336.    >
  337.  > # end of Para\n";
  338. }
  339.  
  340. #------------------------------------------------------------------
  341. # print_uniquepara 
  342. #
  343. # subroutine print_para prints MIF for FrameMaker paragraph
  344.  
  345. sub print_uniquepara {
  346.  
  347.     local($device) = @_[0];
  348.     local($tag) = @_[1];
  349.     local($unique) = @_[2]; 
  350.     local($specialchar) = @_[3]; 
  351.     local($string) = @_[4]; 
  352.  
  353.     print $device " <Para 
  354.   <Unique $unique>
  355.   <PgfTag \`$tag\'>
  356.    <ParaLine $specialchar
  357.     <String \`$string\'>
  358.    >
  359.  > # end of Para\n";
  360. }
  361.  
  362.  
  363.  
  364. #------------------------------------------------------------------
  365. # print_multi 
  366. #
  367. # subroutine print_multi prints MIF for multiple FrameMaker paragraph
  368.  
  369. sub print_multi {
  370.  
  371.     local($tag) = @_[0];
  372.     local(@strings) = split(/\n/, @_[1]); 
  373.  
  374.     foreach $string (@strings)
  375.     {
  376.         if ($string =~ s/^--//)
  377.         {
  378.             &print_specialpara($tag, "<Char Bullet>", $string);
  379.         }
  380.         else
  381.         {
  382.             &print_para($tag, $string);
  383.         }
  384.     }
  385. }
  386.  
  387. #------------------------------------------------------------------
  388. # print_anchor 
  389. #
  390. # subroutine print_anchor prints MIF for FrameMaker anchored frame
  391.  
  392. sub print_anchor {
  393.  
  394.     local($id) = @_[0];
  395.  
  396.     print CHAPTER " <Para 
  397.   <ParaLine 
  398.    <AFrame $id>
  399.   >
  400.  > # end of Para\n";
  401. }
  402.  
  403. #------------------------------------------------------------------
  404. # print_productheader 
  405. #
  406. # subroutine print_chapterheader prints header for every chapter file
  407.  
  408. sub print_productheader {
  409.  
  410.     local($category) = @_[0];
  411.     local($string) = @_[1]; 
  412.  
  413.     print PRODUCT <<PRODUCTHEADER;
  414. <html>
  415. <head>
  416. <title>Solaris - "$category"</title>
  417. </head>
  418. <body>
  419. <A HREF="http://localhost:7999"><IMG SRC="../../../images/goto_toc.gif"> Catalyst Catalog Search Page</A> <A HREF="$string"><IMG SRC="../../../images/goto_back.gif"> Sub-category
  420. <HR>
  421. </A>
  422. PRODUCTHEADER
  423. }
  424.  
  425. #------------------------------------------------------------------
  426. # print_chapterfooter
  427. #
  428. # subroutine print_chapterfooter prints footer for every chapter file
  429.  
  430. sub print_chapterfooter {
  431.  
  432.    print CHAPTER <<CHAPTERFOOTER;
  433. > # end of TextFlow
  434. # End of Generated MIF File for the Sun Solutions Catalog
  435. CHAPTERFOOTER
  436.  
  437. }
  438.  
  439. #------------------------------------------------------------------
  440. # print_section
  441. #
  442. # subroutine print_section prints the section file for every chapter
  443.  
  444. sub print_section {
  445.  
  446.     local($category) = @_;
  447.     local($outputSectionFile, $cnt, $word, @words);
  448.  
  449.     $outputSectionFile = "sect" . $chapterCount . ".mif";
  450.     open(SECTION, ">$outputSectionFile") || do
  451.     {
  452.         die "Can't open SECTION file $outputSectionFile\n";
  453.     };
  454.  
  455.     #----------------------
  456.     # HEADER
  457.     print SECTION <<SECTIONHEADER;
  458. <MIFFile 4.00> # Developed by the Carl Group, Inc
  459. # for the Sun Solutions Catalog
  460. include(../secthead.mif)
  461.  
  462. SECTIONHEADER
  463.  
  464.  
  465.     @words = split(" ", $category);    # place into array
  466.     @words = grep(!/^ $/, @words);    # remove spaces
  467.     $cnt = @words;            # count elements
  468.     if ($cnt == 1)
  469.     {
  470.         &print_uniquepara(SECTION, "Chap Title", 123, "", "");
  471.         &print_uniquepara(SECTION, "Chap Title", 124, "", "");
  472.         &print_uniquepara(SECTION, "Chap Title", 125, "<AFrame 1>", @words[0]);
  473.     }
  474.     elsif ($cnt == 2)
  475.     {
  476.         &print_uniquepara(SECTION, "Chap Title", 123, "", "");
  477.         &print_uniquepara(SECTION, "Chap Title", 124, "", @words[0]);
  478.         &print_uniquepara(SECTION, "Chap Title", 125, "<AFrame 1>", @words[1]);
  479.     }
  480.     elsif ($cnt == 3)
  481.     {
  482.         &print_uniquepara(SECTION, "Chap Title", 123, "", @words[0]);
  483.         &print_uniquepara(SECTION, "Chap Title", 124, "", @words[1]);
  484.         &print_uniquepara(SECTION, "Chap Title", 125, "<AFrame 1>", @words[2]);
  485.     }
  486.  
  487.     print SECTION <<SECTIONBODY;
  488. > # end of TextFlow
  489. <TextFlow 
  490.  <Para 
  491.   <Unique 95>
  492.   <PgfTag `Chap Head'>
  493.   <ParaLine 
  494.    <TextRectID 12>
  495.   >
  496.  > # end of Para
  497.  <Para 
  498.   <Unique 100>
  499.   <PgfTag `Chap Head'>
  500.   <ParaLine 
  501. SECTIONBODY
  502.     print SECTION "   <String `SECTION $chapterCount'>  # Section with Number\n  >\n > # end of Para\n";
  503.  
  504.     #-------------------------
  505.     # FOOTER
  506.     print SECTION <<SECTIONFOOTER;
  507. > # end of TextFlow
  508. # End of MIFFile
  509. SECTIONFOOTER
  510.  
  511.     close SECTION;
  512. }
  513.  
  514. #------------------------------------------------------------------
  515. # createbook
  516. #
  517. # subroutine createbook creates the MIF version of a book
  518.  
  519. sub createbook {
  520.  
  521.         local($bookFile, $chapter);
  522.  
  523.     $bookFile = "ssc.mif";
  524.     open(BOOK, ">$bookFile") || do
  525.     {
  526.         die "Can't open CHAPTER file $bookFile\n";
  527.     };
  528.  
  529.     &print_bookheader();
  530.     for(1..$chapterCount)
  531.     {
  532.         &print_bookcomponent($_);
  533.     }
  534.     &print_bookfooter();
  535.  
  536. }
  537.  
  538.  
  539. #------------------------------------------------------------------
  540. # print_bookheader
  541. #
  542. # subroutine print_bookheader prints MIF header for the book file
  543.  
  544. sub print_bookheader {
  545.  
  546.     print BOOK <<BOOKHEADER
  547. <Book 4.0> # Generated by The Carl Group, Inc
  548. # for the Sun Solutions Catalog
  549. <BookComponent 
  550.  <FileName `<c\\>sscTOC.doc'>
  551.  <FileNameSuffix `TOC'>
  552.  <DeriveLinks No >
  553.  <DeriveType TOC >
  554.  <DeriveTag `H1'>
  555.  <DeriveTag `H2'>
  556.  <StartPageSide ReadFromFile >
  557.  <PageNumbering Continue >
  558.  <PgfNumbering Continue >
  559.  <PageNumPrefix `'>
  560.  <PageNumSuffix `'>
  561.  <DefaultPrint Yes >
  562.  <DefaultApply Yes >
  563.  <DefaultDerive Yes >
  564. > # end of BookComponent
  565. BOOKHEADER
  566.  
  567. }
  568.  
  569. #------------------------------------------------------------------
  570. # print_bookcomponent
  571. #
  572. # subroutine print_bookcomponent prints MIF header for every component in the book file
  573.  
  574. sub print_bookcomponent {
  575.  
  576.         local($component, $section, $chapter) = @_[0];
  577.  
  578.     $section = "sect" . $component . ".doc";
  579.     $chapter = "chap" . $component . ".doc";
  580.  
  581.     print BOOK <<BOOKCOMPONENT
  582. <BookComponent 
  583.  <FileName `<c\\>$section'>
  584.  <StartPageSide ReadFromFile >
  585.  <PageNumbering Continue >
  586.  <PgfNumbering Continue >
  587.  <PageNumPrefix `'>
  588.  <PageNumSuffix `'>
  589.  <DefaultPrint Yes >
  590.  <DefaultApply Yes >
  591. > # end of BookComponent
  592. <BookComponent 
  593.  <FileName `<c\\>$chapter'>
  594.  <StartPageSide ReadFromFile >
  595.  <PageNumbering Continue >
  596.  <PgfNumbering Continue >
  597.  <PageNumPrefix `'>
  598.  <PageNumSuffix `'>
  599.  <DefaultPrint Yes >
  600.  <DefaultApply Yes >
  601. > # end of BookComponent
  602. BOOKCOMPONENT
  603.  
  604. }
  605.  
  606. #------------------------------------------------------------------
  607. # print_bookfooter
  608. #
  609. # subroutine print_bookfooter prints MIF footer for the book file
  610.  
  611. sub print_bookfooter {
  612.  
  613.    print BOOK <<BOOKFOOTER;
  614. <BookComponent 
  615.  <FileName `<c\\>sscIX.doc'>
  616.  <FileNameSuffix `IX'>
  617.  <DeriveLinks No >
  618.  <DeriveType IDX >
  619.  <DeriveTag `Index'>
  620.  <StartPageSide ReadFromFile >
  621.  <PageNumbering Continue >
  622.  <PgfNumbering Continue >
  623.  <PageNumPrefix `'>
  624.  <PageNumSuffix `'>
  625.  <DefaultPrint Yes >
  626.  <DefaultApply Yes >
  627.  <DefaultDerive Yes >
  628. > # end of BookComponent
  629. # end of Book
  630. BOOKFOOTER
  631.  
  632. }
  633.